package com.etool.modules.statistics.parse;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.dom4j.Node;

public class ParseXml {
	public static void main(String[] args) throws DocumentException {
		StringBuffer xml=new StringBuffer();
		xml.append("<root>");
		xml.append("    <params>");
		xml.append("        <param name=\"beginDate\" type=\"date\" value=\"{value:1}\"></param>");
		xml.append("        <param name=\"endDate\" type=\"date\" value=\"{value:-1}\"></param>");
		xml.append("        <param name=\"gender\" type=\"select\" value=\"{value:{0:全部,1:男,2:女}}\"></param>");
		xml.append("        <param name=\"type\" type=\"select\" value=\"{url:'http://www.yuanlai.com/type.do'}\"></param>");
		xml.append("    </params>");
		xml.append("    <output>");
		xml.append("        <thead>");
		xml.append("            <tr>");
		xml.append("                <th field=\"register\">日期</th>");
		xml.append("                <th field=\"userId\">用户Id</th>");
		xml.append("            </tr>");
		xml.append("        </thead>");
		xml.append("        <sql>");
		xml.append("        <![CDATA[ ");
		xml.append("            select register，userId from yuanlai_user.userCore where register>=${beginDate} register<${endDate}");
		xml.append("        ]]>");
		xml.append("        </sql>");
		xml.append("    </output>");
		xml.append("</root>");
		
		Document document = DocumentHelper.parseText(xml.toString());
		
		Element root = document.getRootElement();
		
		Element params=root.element("params");
		
		List<Element> paramArray = params.elements("param");
		
		for(Element param:paramArray)
		{
			String name=param.attribute("name").getValue();
			String type=param.attribute("type").getValue();
			String value=param.attribute("value").getValue();
			
			
			if(StringUtils.equals("date",type))
			{
				ParseDataParams.parse(value);
			}
			if(StringUtils.equals("select",type))
			{
				
			}
			
			if(StringUtils.equals("text",type))
			{
				
			}
			
		}

	}
}


